// Learn TypeScript:
//  - https://docs.cocos.com/creator/manual/en/scripting/typescript.html
// Learn Attribute:
//  - https://docs.cocos.com/creator/manual/en/scripting/reference/attributes.html
// Learn life-cycle callbacks:
//  - https://docs.cocos.com/creator/manual/en/scripting/life-cycle-callbacks.html

import UIPoker from "../../View/UIPoker/UIPoker";
import GameDB, { Poker } from "../GameDB";

const { ccclass, property } = cc._decorator;

//  这是一个预制体，用于生成游戏场景
@ccclass
export default class GameView extends cc.Component {
  @property(cc.Prefab)
  pokerPerfab: cc.Prefab = null
  
  // 初始化区域
  @property(cc.Node)
  initPokerArea: cc.Node = null

  // 一开始放牌区
  @property(cc.Node)
  closeSendArea: cc.Node = null

  // 开牌区
  @property(cc.Node)
  openSendArea: cc.Node = null

  // 收牌区
  @property([cc.Node])
  receiveAreaList: cc.Node[] = []


  @property(cc.Node)
  playGroupAnchor: cc.Node = null

  private playGroupList: cc.Node[] = []
  private m_GameDB: GameDB = null



  public InitPokers(pokers: Poker[]) {
    // 创建所有的扑克牌UI
    pokers.forEach((poker, index) => {
      let uiPoker = this.CreateUIPoker(poker)
      uiPoker.node.x = 0.5 * index
      this.initPokerArea.addChild(uiPoker.node)
    })
  }

  public CreateUIPoker(poker: Poker): UIPoker {
    let uiPokerNode = cc.instantiate(this.pokerPerfab)
    let uiPoker: UIPoker = uiPokerNode.getComponent(UIPoker)
    uiPoker.Init(poker)
    return uiPoker
  }

}
